class Solution {
public:
    int numberOfArithmeticSlices(vector<int>& nums) {
        int n = nums.size();
        vector<int> dp(n, 0);
        int sum = 0;
        for(int i = 2; i < n; i++)
        {
            dp[i] = nums[i] - nums[i - 1] == nums[i - 1] - nums[i - 2] ? dp[i - 1] + 1 : 0;
            sum += dp[i];
        }

        return sum;
    }
};

class Solution {
public:
    int maxTurbulenceSize(vector<int>& arr) {
        int n = arr.size();
        vector<int> f(n, 1), g(n, 1);
        int _max = 1;
        for (int i = 1; i < n; i++) {
            if (arr[i] < arr[i - 1]) {
                g[i] = f[i - 1] + 1;
            } else if (arr[i] > arr[i - 1]) {
                f[i] = g[i - 1] + 1;
            }
            _max = max(_max, max(f[i], g[i]));
        }

        return _max;
    }
};